package factory;

import java.io.File;
import java.util.Scanner;

/**
 * @author Steve
 * Menu Driver
 */
public class MenuStarter{

	/**
	 * Sets store name.  Enter Baskin Robins or Donkin Donuts, 
	 * anything else will default to both.
	 * @param store name of store (no spaces)
	 */
	public static void setStore(String store){	
		if(store.equalsIgnoreCase("Baskin Robins"))
			LoadableMenu.setFilename("resources/baskin");
		else if (store.equalsIgnoreCase("Donkin Donuts"))
			LoadableMenu.setFilename("resources/dunkin");
	}

	/**
	 * Remember to set store type otherwise this
	 * will allow the selection from both stores.
	 * @return OrderObject
	 */
	public static OrderObject getOrder(){
		LoadableMenu menu = LoadableMenu.getInstance();

		Scanner in = new Scanner(System.in);

		return menu.getOrder(in);
	}

	/**
	 * Returns Options chosen.  If not called, Menu will assume the store is both.
	 * This should be called first as, once the getOrder is called, you cannot make 
	 * any changes to the options
	 * @return OrderObject
	 */
	public static OrderObject getOption(){
		String loc = "resources/options";
		try {
			Scanner input = new Scanner(new File(loc));
			LoadableMenu oMenu = LoadableMenu.load(input);

			input.close();

			Scanner in = new Scanner(System.in);

			return oMenu.getOrder(in);
		} catch(Throwable t){ 
			t.printStackTrace(); 
			System.err.println("FATAL: Could not load config file " + loc + " - Exiting..."); 
			System.exit(-1); 
		}
		return null;
	}


	/**
	 * Test cases
	 * @param args
	 */
	public static void main(String[] args){
//		args = new String[] {"resources/menu","resources/options"};	
//		getOption();
//		System.out.println(getOption().toLine());
//		getOrder();
//
//		setStore("DonkinDonuts");
//		System.out.println(getOrder().toLine());
	}
}
